/**
 *  Copyright 2002-2009 the original author or authors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package foo.bar.wiki.security;

import foo.bar.wiki.domain.Role;
import foo.bar.wiki.domain.User;
import foo.bar.wiki.utils.CollectionUtils;
import foo.bar.wiki.utils.Transformer;

import java.util.Set;
import java.util.List;
import java.util.LinkedHashSet;

/**
 * Transform a {@link User}'s {@link Role} to a set of jSecurity usable roles, it's just the name of
 * {@link foo.bar.wiki.security.RoleType} in {@link Role}
 * 
 * @author tmjee
 * @version $Date: 2009-03-14 14:53:07 +0800 (Sat, 14 Mar 2009) $ $Id$
 */
public class UserRoleToJSecurityRoleAsStringTransformer implements Transformer<User, Set<String>> {
    
    public Set<String> transform(User user) {
        return new LinkedHashSet<String>(CollectionUtils.collect(user.getRoles(), new RoleToStringTransformer()));
    }


    class RoleToStringTransformer implements Transformer<Role, String> {

        public String transform(Role o) {
            return o.getType().name();
        }
    }
}
